from django.contrib import admin

from app.admin import SimpleModelAdmin, AutoUpdateUserModelAdmin
from product.models import *


@admin.register(ProductStyle)
class ProductStyleAdmin(SimpleModelAdmin):
    list_display = ['pk', 'name_cn', 'name_en', 'desc_cn', 'desc_en']
    list_display_links = ['pk', 'name_cn']
    search_fields = ['name_cn', 'name_en']


@admin.register(ProductCategory)
class ProductCategoryAdmin(SimpleModelAdmin):
    list_display = ['pk', 'name_cn', 'name_en']
    list_display_links = ['pk',  'name_cn', 'name_en']
    search_fields = ['name_cn', 'name_en']


@admin.register(ProductInfo)
class ProductInfoAdmin(SimpleModelAdmin):
    list_display = [
        'pk', 'name_cn', 'name_en', 'is_beer', 'abv', 'plato', 'ibu', 'bottle_size',
        'main_image', 'barcode', 'product_style', 'desc_cn', 'desc_en']
    list_display_links = ['pk', 'name_cn']
    autocomplete_fields = ['product_style']
    list_filter = ['is_beer', 'product_style']
    search_fields = ['name_cn', 'name_en', 'barcode']


@admin.register(ProductBatch)
class ProductBatchAdmin(SimpleModelAdmin):
    list_display = ['pk', 'product_info', 'production_date', 'expiration_date']
    list_display_links = ['pk', 'product_info']
    list_filter = ['product_info']
    autocomplete_fields = ['product_info']
    search_fields = ['product_info__name_cn', 'product_info__name_en']


@admin.register(ProductIn)
class ProductInAdmin(AutoUpdateUserModelAdmin):
    list_display = ['pk', 'product_batch', 'amount', 'date_in', 'notes']
    list_display_links = ['pk', 'product_batch']
    list_filter = ['date_in']
    search_fields = ['notes']
    autocomplete_fields = ['product_batch']


@admin.register(ProductSales)
class ProductSalesAdmin(SimpleModelAdmin):
    list_display = [
        'pk', 'product_batch', 'price_show',
        'amount_initial', 'current_sales', 'amount_left', 'amount_per_user_max', 'is_vip_only',
        'main_image', 'show_start', 'sales_start', 'sales_end', 'is_show'
    ]
    list_display_links = ['pk', 'product_batch']
    list_filter = [
        'product_batch', 'is_show', 'product_category', 'is_vip_only', 'vip_level',
        'sales_start', 'sales_end'
    ]
    list_editable = ['is_show']
    filter_horizontal = ['vip_level', 'product_category']
    autocomplete_fields = ['product_batch']
    search_fields = ['product_batch__product_info__name_cn']


@admin.register(Banner)
class BannerAdmin(SimpleModelAdmin):
    list_display = [
        'pk', 'name_cn', 'order_index', 'show_start', 'banner_image', 'jump_url', 'product_sales', 'is_show', ]
    list_display_links = ['pk', 'name_cn']
    list_editable = ['is_show']
    list_filter = ['product_sales', 'is_show']
    autocomplete_fields = ['product_sales']
    search_fields = ['product_sales__product_batch__product_info__name_cn']


@admin.register(HotSearch)
class HotSearchAdmin(SimpleModelAdmin):
    list_display = ['pk', 'key_word', 'count', 'is_show']
    list_display_links = ['pk', 'key_word']
    list_editable = ['is_show']
    list_filter = ['is_show']
    search_fields = ['key_word']
